import { getRandomElements, HostEnum, type GameJson } from "~/utils";
import { getServerCache } from "../plugins/cache";

/** 随机获取24个游戏 */
export default defineEventHandler(async (event): Promise<GameJson[]> => {
  const { hostName = HostEnum.localhost, count = 24 } = await readBody(event);
  const { allGameJson = [] } = getServerCache().gameJsonDataSource[hostName];
  return getRandomElements(allGameJson, count);
});
